package com.sportschain.app.core.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx;
import com.sportschain.app.R;
import com.sportschain.app.circle.CircleFragment;
import com.sportschain.app.core.adapter.SimpleFragmentPagerAdapter;
import com.sportschain.app.core.base.BaseActivity;
import com.sportschain.app.core.utils.SharedPreConstants;
import com.sportschain.app.core.utils.SharedPreUtil;
import com.sportschain.app.homepage.HomepageFragment;
import com.sportschain.app.mine.MineFragment;
import com.sportschain.app.shop.ShopFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MainActivity extends BaseActivity {

    @BindView(R.id.container_vp)
    ViewPager mContainerVp;
    @BindView(R.id.bottom_navigation_bar)
    BottomNavigationViewEx mBottomNavigationBar;


    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        checkInitState();
        mBottomNavigationBar.setTextSize(12);
        mBottomNavigationBar.enableShiftingMode(false);
        mBottomNavigationBar.enableItemShiftingMode(false);
        mBottomNavigationBar.enableAnimation(false);
        mBottomNavigationBar.setItemIconTintList(null);
    }

    @Override
    public void initData() {
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(HomepageFragment.newInstance());
        fragmentList.add(ShopFragment.newInstance());
        fragmentList.add(CircleFragment.newInstance());
        fragmentList.add(MineFragment.newInstance());

        SimpleFragmentPagerAdapter fragmentPagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);
        mContainerVp.setAdapter(fragmentPagerAdapter);

        mBottomNavigationBar.setupWithViewPager(mContainerVp);
    }

    @Override
    public void initListener() {

    }

    private void checkInitState() {
        boolean isFirstInit = SharedPreUtil.getBooleanValue(mActivity, SharedPreConstants.isFirstInit, true);
        if (isFirstInit) {
            startActivity(SplashActivity.class);
            SharedPreUtil.putBooleanValue(mActivity, SharedPreConstants.isFirstInit, false);
        }
    }
}
